package com.minhua.jijiehao2.mainframe.loan.loanfragment.impl

import com.minhua.jijiehao2.base.BaseMvpPresenter
import com.minhua.jijiehao2.bean.BaseBean
import com.minhua.jijiehao2.bean.ChannelBean
import com.minhua.jijiehao2.bean.GridBean
import com.minhua.jijiehao2.constants.DefineKey
import com.minhua.jijiehao2.http.CallBack
import com.minhua.jijiehao2.http.ParamsMap
import com.minhua.jijiehao2.mainframe.loan.loanfragment.imp.ILoanPresenter
import com.minhua.jijiehao2.mainframe.loan.loanfragment.imp.ILoanView

class LoanPresenter : BaseMvpPresenter<ILoanView>(), ILoanPresenter {

    private var mLoanModel = LoanModel()
    private var currentPage = 1

    override fun getMoneyList(): List<GridBean> = mLoanModel.getMoneyList()

    override fun getDateList(): List<GridBean> = mLoanModel.getDateList()

    override fun getListChannel() {
        currentPage = 1
        doGetListChannel()
    }

    override fun loadMoreListChannel() {
        currentPage++
        doGetListChannel()
    }

    private fun doGetListChannel() {
        val map = ParamsMap()
        map.put(DefineKey.MONEY_INDEX, v?.getMoneyIndex() ?: 0)
        map.put(DefineKey.DATE_INDEX, v?.getDateIndex() ?: 0)
        map.put(DefineKey.CURRENT_PAGE, currentPage)
        mLoanModel.getChannelList(map, object : CallBack<List<ChannelBean>>() {
            override fun onSuccess(t: BaseBean<List<ChannelBean>>) {
                v?.onChannelSuccess(t.data!!, currentPage == 1)
            }
        })
    }
}